Component({
  properties: {
    listsHidden: {
      type: Boolean,
      value: false
    },
    goodsMsg: {
      type: Array,
      value: [],
    },
    btnActive: {
      type: String,
      value: 'true',
    },
  },
  data: {
    showBtn: false,
    showCom: false,
    emptyHidden: true,
    cartsData: [{
        storeName: '娃哈哈旗舰店',
        total: 0,
        childrenGoods: [{
            goodsName: 'PUMA 彪马官方 男子卫衣 Archive LOGO 573847',
            speci: '规格1',
            price: '128.30',
            num: 2,
            img: '../../images/boy_s.png'
            // selected: false,
          },
          {
            goodsName: '店铺1的商品2',
            speci: '规格2',
            price: '531.89',
            num: 5,
            img: '../../images/boy_s.png'
            // selected: false,
          },
          {
            goodsName: '店铺1的商品3',
            speci: '规格3',
            price: '308.18',
            num: 1,
            img: '../../images/boy_s.png'
            // selected: false,
          },
        ]
      }, {
        storeName: '店2',
        total: 0,
        childrenGoods: [{
          goodsName: '店铺2的商品1',
          speci: '规格1',
          price: '266.30',
          num: 3,
          img: '../../images/boy_s.png'
          // selected: false,
        }, ]
      },
      {
        storeName: '店铺1',
        total: 0,
        childrenGoods: [{
            goodsName: '店铺1的商品1',
            speci: '规格1',
            price: '128.30',
            num: 8,
            img: '../../images/boy_s.png'
            // selected: false,
          },
          {
            goodsName: '店铺1的商品2',
            speci: '规格2',
            price: '531.89',
            num: 4,
            img: '../../images/boy_s.png'
            // selected: false,
          },
        ]
      },
    ],
  },
  methods: {
    // onChange(event) {
    //   wx.showToast({
    //     title: `切换到标签 ${event.detail.index + 1}`,
    //     icon: 'none'
    //   });
    // },
    imputedPrice(e) { //计算总价

      // this.setData({
      //   allNum: 0,
      //   allPrice: 0,

      // })
      // console.log(this.properties.goodsMsg);
      for (let i in this.properties.goodsMsg) { //遍历商铺
        let childrenLists = this.properties.goodsMsg[i].childrenGoods
        this.setData({ //小计价格初始化
          ['goodsMsg[' + i + '].total']: 0
        })

        for (let j in childrenLists) { //遍历商品
          // console.log(j)
          this.setData({
            ['goodsMsg[' + i + '].total']: this.properties.goodsMsg[i].total + childrenLists[j].price * childrenLists[j].num
          })
        }
        //小计取整
        // console.log(this.data.cartsData[i].total)
        this.setData({
          ['goodsMsg[' + i + '].total']: (this.properties.goodsMsg[i].total).toFixed(2)
        })

      }

      // console.log(this.data.allPrice)
    },
    naviTo(e) {
      // console.log(e)
      if (e.currentTarget.dataset.type == 'pay') {
        wx.navigateTo({
          url: '../order/order',
        })
      } else if (e.currentTarget.dataset.type == 'com') {
        wx.navigateTo({
          url: '../evaluate/evaluate?goods=' + JSON.stringify(e.currentTarget.dataset.goods),
        })
      }

    },
  },

  attached: function() {
    // 在组件实例进入页面节点树时执行

    // console.log(window)
    if (this.properties.btnActive == '1') { //支付按钮的显示或隐藏
      this.setData({
        showBtn: false,
        showCom: true
      })
      // this.data.showBtn = true
    } else if (this.properties.btnActive == '3') {
      this.setData({
        showBtn: true,
        showCom: false
      })
      // this.data.showBtn = false
    } else {
      this.setData({
        showBtn: true,
        showCom: true
      })
      // this.data.showBtn = false
    }

    // console.log(this.properties.goodsMsg.length)
    if (this.properties.goodsMsg.length == 0) { //组件的显示或隐藏
      this.setData({
        emptyHidden: false
      })
    }


    // console.log(this)
    this.imputedPrice()

    // this.onPageScroll()


  },
  detached: function() {
    // 在组件实例被从页面节点树移除时执行
  },
})